/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.maxato.services;

import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import nl.maxato.domain.Athlete;
import nl.maxato.domain.Club;
import nl.maxato.domain.Wage;
import nl.maxato.xmlservices.ConvertXMLData;
import nl.maxato.xmlservices.XMLService;

/**
 *
 * @author Danny
 */
public class CalculateWages {

    double foreignWage = 1.2;
    XMLService xmlService;

    public CalculateWages() {
        xmlService = XMLService.getInstance();
    }

    public List<Wage> calculateWageForNextSeason(Double maxid, Double fans, Double constant, List<Athlete> athletes, ResourceBundle rb) {
        List<Wage> wages = new ArrayList<Wage>();
        Wage w = null;
        Club club = xmlService.convertClubData();
        for (int i = 0; i < athletes.size(); i++) {
            String foreigner = rb.getString("NO");
            if (athletes.get(i).getAge() >= 17) {
                double value = 0;
                value = (athletes.get(i).getMaxid() * maxid) + (athletes.get(i).getFans() * fans) - constant;

                if (!Integer.toString(athletes.get(i).getNationId()).equals(club.getNationId())) {
                    value = value * 1.2;
                    foreigner = rb.getString("YES");
                }
                w = new Wage(athletes.get(i), foreigner, (int) Math.round(value));
            } else {
                w = new Wage(athletes.get(i), foreigner, 0);
            }
            wages.add(w);
        }
        return wages;
    }
}
